<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>订单管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${s.base}/css/base/base.css" media="all" />
</head>
<body class="childrenBody">
	<blockquote class="layui-elem-quote quoteBox">
		<form class="layui-form">
			<input type="hidden" name="formId" value="${formId}" />
			<div class="layui-inline">
				<label class="layui-input-inline">领导姓名：</label>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" name="name" id="name" placeholder="请输入领导姓名" />
				</div>
				<a class="layui-btn search_btn" data-type="reload">搜索</a>
				<a class="layui-btn layui-btn-normal add_btn">添加</a>
			</div>

		</form>
	</blockquote>
	<table id="entityList" lay-filter="entityList"></table>



<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript" src="${s.base}/js/base/time.js"></script>
<script type="text/javascript">
	var kind="${kind}";
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;
        //列表
        var tableIns = table.render({
            elem: '#entityList',
            url : '/leader/jsonList',
            cellMinWidth : 95,
            page : true,
            height : "full-125",
            limit : 20,
            method:'post',
            limits : [10,15,20,25],
            id : "entityList",
            cols : [[
                {type: 'numbers', title: '序号'},
                {field: 'name', title: '领导姓名',align:'center'},
                {field: 'departmentName', title: '部门',align:'center', sort: true},
                {field: 'num', title: '编号',align:'center', sort: true},
                {field: 'createTime', title: '创建时间',align:'center',width:160, templet:function(d){
                    if(d.createTime==null||d.createTime==""){
                        return "";
                    }else{
                        return timeStamp2String(d.createTime);
                    }
                }},
                {title: '操作',width:170,align:"center", templet:function(d){
                    return '<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>'+
                    '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>';
                }}
            ]]
        });
        //搜索
        $(".search_btn").on("click",function(){
            table.reload("entityList",{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    name: $("#name").val()
                }
            })
        });

        //增加/编辑
        function addEntity(params){
            var title="编辑";
            if(params==null||params==""){
                title="添加"
            }
            var index = layui.layer.open({
                title :title,
                type : 2,
                content : "/leader/selectEntity"+params,
                success : function(layero, index){
                    var body = layui.layer.getChildFrame('body', index);
                    body.find(".closeLay").bind("click",function () {
                        layui.layer.close(index);
                    })
                    layui.layer.full(index);
                }
            });
        }
        $(".add_btn").click(function(){
            addEntity('');
        })

        //列表操作
        table.on('tool(entityList)', function(obj){
            var layEvent = obj.event,
                data = obj.data;
            if(layEvent === 'edit'){ //编辑
                addEntity("?id="+data.id);
            } else if(layEvent === 'del'){ //删除
                layer.confirm('是否删除部门【'+data.name+'】吗？',{icon:3, title:'提示信息'},function(index){
                    $.get("/leader/deleteEntity",{
                        "id":data.id,
                        "_method":"DELETE"
                    },function(result){
                        if(1==result.returnInfo.state){
                            tableIns.reload();
                            layer.close(index);
                        }else{
                            top.layer.msg(result.returnInfo.errorMsg);
                        }
                    })
                });
            }
        });

    })
</script>
</body>
</html>